package com.ruiao.tools.dongtaiguankong;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import androidx.core.app.ActivityCompat;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.ruiao.tools.dongtaiguankong.DongtaiBaojing.TaskBean;

import com.ruiao.tools.R;


import java.io.File;
import java.util.ArrayList;



public class EndTaskActivity extends BaseAppCompatActivity  {
    private LinearLayout tasktip;
    private TaskBean bean;

    private ImageView img1;
    private ArrayList<Uri> imgList;
    private Button btn;

    private EditText log;
    private boolean hasphoto = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        bean = (TaskBean) getIntent().getSerializableExtra("task");
        imgList = new ArrayList<>();
        initData();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }

    private void initData() {
        File file1 = new File(Environment.getExternalStorageDirectory(), "/yunwei/" + 3 + ".jpg");
        if(file1.exists()){
            file1.delete();
        }
        imgList.add(Uri.fromFile(file1));
    }

    @Override
    protected void initView() {
        tasktip = findViewById(R.id.tasktip);
        log = findViewById(R.id.et_log);
        btn = findViewById(R.id.btn_next);
        img1 = findViewById(R.id.img1);
        img1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {


            }
        });
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(!hasphoto){

                    return;
                }
                if (lacksPermissions(PERMISSION)) {

                    ActivityCompat.requestPermissions(EndTaskActivity.this, PERMISSION, OPEN_SET_REQUEST_CODE);

                } else {

                    // Log.i(TAG, "已经全部打开权限");

                }
            }


        });

    }
//    private void updata() {
//
//
//
//
//        RequestParams pa = new RequestParams();
//        pa.put("taskname",bean.id);
//        pa.put("Action","h");
//        pa.put("GPS_J_2",""+lon);
//        pa.put("GPS_W_2",""+lat);
//        String ss = log.getText().toString();
//        ss.trim();
//        String strBase64 = Base64.encodeToString(ss.getBytes(), Base64.DEFAULT);
//        pa.put("tasklog",strBase64);
//
//
//
//    }
    @Override
    public String SetTitle() {
        return "完成运维";
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_end_task;
    }






    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (requestCode == OPEN_SET_REQUEST_CODE) {

            if (hasAllPermissionsGranted(grantResults)) {

//                Log.i(TAG, "用户允许打开权限");

            } else {

//                Log.i(TAG, "用户拒绝打开权限");

                showPermissionDialog("请去设置页面打开权限", OPEN_SET_REQUEST_CODE);
            }

        }

    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {

        super.onSaveInstanceState(outState);
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == OPEN_SET_REQUEST_CODE) {
            if (lacksPermissions(PERMISSION)) {

//                Log.i(TAG, "缺少权限去申请");

                ActivityCompat.requestPermissions(this, PERMISSION, OPEN_SET_REQUEST_CODE);
            }
        }
    }


}
